home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / testdemo.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  105 lines

  1. ; $Id: testdemo.pro,v 1.6 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;
  6. ;    Main program to run a demonstration program.
  7. ;
  8. ; This IDL program reads a script file, showing each line that is executed
  9. ;    and waiting a fixed period of time after each statement is executed.
  10. ; The first character of each line has the following significance:
  11. ;    ;  for comment, line is printed and there is no wait.
  12. ;    @  to execute a new file.
  13. ;    All others, statement to be executed.
  14. ; You can run it with a different delay (default = 1.0 seconds) by setting
  15. ;    demo$delay to the desired period.
  16. ;
  17. demo$line  = ''            ;null string for input strings
  18. demo$msg = 'IO Error occured'    ;assume error
  19. if n_elements(demo$delay) eq 0 then demo$delay = 1.0 ;wait between statements
  20.  
  21. if n_elements(demo$file) eq 0 then begin ;Define the default script
  22.     demo$file = filepath('testdemo.demo',subdirectory='lib')
  23.     qq = findfile(demo$file, count=i)
  24.     if i eq 0 then begin    ;Cant find script.
  25.         print,"Can't find the demo script ",demo$file
  26.         read,'Enter script file path name: ',demo$file
  27.         endif
  28.     endif
  29.  
  30. if n_elements(demo$rept) eq 0 then demo$rept = 1    ;Def Repetition count
  31.  
  32. if n_elements(demo$color) eq 0 then begin    ;defining config?
  33.     demo$imagedir = filepath('',subdir=['examples', 'data'])
  34.     if n_elements(findfile(demo$imagedir + '*.dat')) le 2 then begin
  35.         print,'Cant find images on: ',demo$imagedir
  36.         read,'Enter directory containing images: ', demo$imagedir
  37.         endif
  38.     case !version.os of
  39.         'vms':
  40.         'Win32':
  41.         'MacOS':
  42.         else: demo$imagedir=demo$imagedir+'/'
  43.     endcase
  44.     if !d.name eq 'SUN' then window,col=240    ;don't use all colors
  45.     if !d.name eq 'X' then window
  46.     demo$color = 1        ;always do images
  47. endif                ;config
  48.  
  49. on_ioerror, io_err    ;Error branch
  50. get_lun, demo$lun    ;get a unit for program file
  51. t0 = systime(1)        ;Beginning time
  52. wait_time = 0        ;Time spent waiting
  53.  
  54.  
  55. for demo$irept = 1L,demo$rept do begin    ;main loop
  56.     demo$done = 0            ;set to quit
  57.     openr,demo$lun,demo$file,err=i    ;open program file
  58.     if i ne 0 then begin        ;Cant find file
  59. file_err:    print," "
  60.         print,"Can't find file ",demo$file," in current directory."
  61.         print,"You should 'cd' to the directory containing this file and then run idl."
  62.         print," Which is usually ",$
  63.                         filepath('', subdir='lib')
  64.         stop
  65.         endif
  66.     while not (eof(demo$lun) or demo$done) do begin    ;statement loop
  67.         readf,demo$lun,demo$line    ;read statement
  68.             ;print comments without delay
  69.         demo$char = strmid(demo$line,0,1) ;get 1st char
  70.         case demo$char of
  71. ';':         print,demo$line    ;just print comments
  72. '@':         begin            ;open new file
  73.           close,demo$lun
  74.           demo$file = strmid(demo$line,1,100) ;New file name
  75.           ofile = demo$file    ;orig name
  76.           junk = findfile(demo$file,count=i)
  77.             ;Assume in library if not found
  78.           if i eq 0 then demo$file = filepath(demo$file, subdir='lib')
  79.           junk = findfile(demo$file,count=i)
  80.           if i eq 0 then begin
  81.             print,"Cant find script file ",ofile
  82.             read,"Enter pathname of script file ",demo$file
  83.             endif
  84.           openr,demo$lun,demo$file,err=i
  85.           if i ne 0 then goto, file_err
  86.           endcase
  87. else:         begin        ;execute statement
  88.           print, demo$line
  89.           demo$istat = execute(demo$line) ;execute it
  90.           wait, demo$delay    ;allow it to sink in
  91.           wait_time = wait_time + 1
  92.           endcase
  93.         endcase            
  94.         endwhile        ;eof
  95.     close, demo$lun            ;done with file
  96. endfor            ;execute loop
  97.  
  98. demo$msg = 'Done.'
  99. t0 = fix(systime(1) - t0)    ;Total time
  100. wait_time = fix(wait_time * demo$delay)
  101. print,'Times: Elapsed =',t0,', Waiting =',wait_time,', Executing =',$
  102.     t0-wait_time
  103. io_err:    stop, demo$msg
  104. end
  105.